home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / FIX_YTAB < prev    next >
Text File  |  1991-10-05  |  2KB  |  82 lines

  1. #!/bin/sh
  2. #
  3. # This script removes bison's use of alloca()
  4. #
  5. # If the parser stack overflows, bison reallocates the stack using
  6. # alloca().  The chance of parser overflow on an awk program is nil,
  7. # and since mawk never uses alloca() and some systems don't have it
  8. # the most portable solution is to #if 0  it out
  9. #
  10. # This script only works with bison 1.14
  11. #
  12. # If you use an earlier version of bison, look for the line
  13. # tested for in state == 2 below.  This is the push of a new
  14. # state on the parser stack.  You want to make overflow work
  15. # like this:
  16.  
  17. #      if ( parser stack overflow )
  18. #      { errmsg(0, "parser stack overflow") ; exit(1) ; }
  19.  
  20. # Alternatively, if you have alloca() don't do anything, you'll
  21. # get a little dead code. Or upgrade your bison.
  22. #
  23.  
  24. # Also with bison 1.14, two arrays yyphrs[] and yyrhs[] slip
  25. # through that aren't needed if YYDEBUG == 0 so this script
  26. # also puts #if YYDEBUG != 0  conditionals around them.  This
  27. # only matters to those with small (64K) or so memory.
  28.  
  29. # This script is useful for any bison output to be used for
  30. # example under MsDOS with a small model program.
  31.  
  32.  
  33. awk_program='
  34.  
  35. BEGIN { state = 0 }
  36.  
  37. NR==2 && !/Bison/ {
  38.   print "fix_ytab: y.tab.c is not Bison output" | "cat 1>&2"
  39.   exit 1
  40. }
  41.  
  42.  
  43. state == 0 && /^static const short yyprhs\[\] = {/ {
  44.  
  45.   print "#if YYDEBUG != 0"
  46.   print
  47.   state = 1
  48.   next
  49. }
  50.  
  51.  
  52. state == 1 && /^#if YYDEBUG/ {
  53.  
  54.   print "#endif"
  55.   print 
  56.   state = 2
  57.   next
  58. }
  59.  
  60. state == 2 && /^[ \t]*if \(yyssp >= yyss \+ yystacksize - 1\)/ {
  61.  
  62.    print ; getline ; print
  63.    print "\t/* this can never happen */"
  64.    print "\terrmsg(0 , \"parser stack overflow\") ; exit(1) ;"
  65.    print "#if 0"
  66.    state = 3
  67.    next
  68. }
  69.  
  70. state == 3 && /YYABORT/ {
  71.    print
  72.    print "#endif  /* if 0 */"
  73.    state = 4
  74.    next
  75. }
  76.  
  77. { print }'
  78.      
  79.     
  80.  
  81. awk "$awk_program"  $*
  82.